
package sw6.visualschedule.entities;

import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;

public enum Day {
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY,
    SUNDAY;

    @Override
    public String toString() {
        final DateFormatSymbols dfs = new DateFormatSymbols();
        final String[] weekDays = dfs.getWeekdays();

        String result;

        switch (this) {
            case MONDAY:
                result = weekDays[Calendar.MONDAY];
                break;
            case TUESDAY:
                result = weekDays[Calendar.TUESDAY];
                break;
            case WEDNESDAY:
                result = weekDays[Calendar.WEDNESDAY];
                break;
            case THURSDAY:
                result = weekDays[Calendar.THURSDAY];
                break;
            case FRIDAY:
                result = weekDays[Calendar.FRIDAY];
                break;
            case SATURDAY:
                result = weekDays[Calendar.SATURDAY];
                break;
            case SUNDAY:
                result = weekDays[Calendar.SUNDAY];
                break;
            default:
                result = super.toString();
                break;
        }

        return result;
    }

    /**
     * Returns a Day from a Gregorian Calendar.
     * 
     * @param day   the day number from a gregorian calendar. 
     * @return the matching Day enum.
     */
    public static Day fromGregorianCalendar(final int day) {
        Day result;

        switch (day) {
            case GregorianCalendar.MONDAY:
                result = Day.MONDAY;
                break;
            case GregorianCalendar.TUESDAY:
                result = Day.TUESDAY;
                break;
            case GregorianCalendar.WEDNESDAY:
                result = Day.WEDNESDAY;
                break;
            case GregorianCalendar.THURSDAY:
                result = Day.THURSDAY;
                break;
            case GregorianCalendar.FRIDAY:
                result = Day.FRIDAY;
                break;
            case GregorianCalendar.SATURDAY:
                result = Day.SATURDAY;
                break;
            case GregorianCalendar.SUNDAY:
                result = Day.SUNDAY;
                break;
            default:
                result = null;
                break;
        }

        return result;
    }
}
